<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script type="text/javascript" src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=cfEm7GklrF9kQbBPgkTjUwfP5mhYMgMr"></script>
  <script src="https://code.bdstatic.com/npm/jquery@1.12.4/dist/jquery.min.js"></script>
  <title>百度地图</title>
  <style>
    body,html{
      width: 100%;
      height: 100%;
      padding: 0;
      margin: 0;
    }
    #container{
      width: 100%;
      height: 100%;
      overflow: hidden;
    }
    #result{
      position: fixed;
      top: 10px;
      right: 10px;
      padding: 0px 7px;
      min-width: 350px;
      height: 70px;
      line-height: 35px;
      background: #fff;
      box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);
      border-radius: 7px;
      z-index: 99;
    }
  </style>
</head>
<body>
<div id='container'></div>
<div id='result'>
  点击展示详细的地址：
  <div id='result_l'></div>
</div>
<script>
  //实例化地图
  var map = new BMapGL.Map('container');
  map.centerAndZoom(new BMapGL.Point(112.615762, 26.880288), 13);
  var geoc = new BMapGL.Geocoder();
  map.addEventListener('click', function(e){
    //清除地图上所有的覆盖物
    map.clearOverlays();
    // console.log(e);
    var pt = e.latlng;
    var marker = new BMapGL.Marker(new BMapGL.Point(pt.lng, pt.lat));
    map.addOverlay(marker);
    geoc.getLocation(pt, function(rs){
      var addComp = rs.addressComponents;
      $('#result_l').text(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
      let targetWindow = window.opener;
      // 发送消息
      targetWindow.postMessage(addComp.province + addComp.city +  addComp.district + addComp.street + addComp.streetNumber, "*");
      console.log(addComp.province + addComp.city +  addComp.district + addComp.street + addComp.streetNumber);

    })
  })

  var scaleCtrl = new BMapGL.ScaleControl();  // 添加比例尺控件
  map.addControl(scaleCtrl);
  var zoomCtrl = new BMapGL.ZoomControl();  // 添加缩放控件
  map.addControl(zoomCtrl);
  var cityCtrl = new BMapGL.CityListControl();  // 添加城市列表控件
  map.addControl(cityCtrl);
</script>
</body>
</html>